﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace XNADota.Graphics.Techniques
{
    public class Material
    {
        public static readonly Vector3 DefaultDiffuseColor = new Vector3(0.5f, 0.5f, 0.5f);
        public static readonly Vector3 DefaultSpecularColor = new Vector3(0.5f, 0.5f, 0.5f);
        public static readonly Vector3 DefaultAmbientLightColor = new Vector3(0.8f, 0.8f, 0.8f);
        public static readonly ERenderState DefaultRenderStates = ERenderState.Opaque | ERenderState.EnableDepth | ERenderState.NoCull | ERenderState.Solid;

        private ERenderState _RenderStates;

        private Vector3 _DiffuseColor;
        private Vector3 _SpecularColor;
        private Vector3 _AmbientLightColor;

        private Matrix _View;
        private Matrix _Projection;

        public Matrix View
        {
            get { return _View; }
            set { _View = value; }
        }

        public Matrix Projection
        {
            get { return _Projection; }
            set { _Projection = value; }
        }

        public bool Equals(Material instance)
        {
            return _DiffuseColor.Equals(instance._DiffuseColor) &&
                   _SpecularColor.Equals(instance._SpecularColor) &&
                   _AmbientLightColor.Equals(instance._AmbientLightColor);
        }

        public Material()
        {
            _RenderStates = DefaultRenderStates;

            _DiffuseColor = DefaultDiffuseColor;
            _SpecularColor = DefaultSpecularColor;
            _AmbientLightColor = DefaultAmbientLightColor;
        }

        public void ApplyEffect(BasicEffect effect)
        {
            effect.DiffuseColor = _DiffuseColor;
            effect.SpecularColor = _SpecularColor;
            effect.AmbientLightColor = _AmbientLightColor;

            effect.View = _View;
            effect.Projection = _Projection;
        }
    }
}
